<?php

namespace App\Http\Controllers\Unity;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class AiBuildingController extends Controller
{

    public function fakeData()
    {
        if (Cache::has(env('JUHE_WEATHET_CACHE_KEY'))) {
            $data = Cache::get(env('JUHE_WEATHET_CACHE_KEY'));
            $weatherInfo = [
                'temperature' => $data['result']['future'][0]['temperature'],
                'weather' => $data['result']['future'][0]['weather'],
                'direct' => $data['result']['future'][0]['direct']
            ];
        } else {
            $weatherInfo = [
                'temperature' => random_int(12, 23). '/' . random_int(23, 35) . '℃',
                'weather' => '多云',
                'direct' => '东北风'
            ];
        }
        $airCondition = [
            'inside' => [
                'pm2.5' => random_int(20, 40),
                'pm10' => random_int(50, 60),
            ],
            'outside' => [
                'pm2.5' => random_int(20, 40),
                'pm10' => random_int(50, 60),
            ]
        ];
        $date = [
            'month' => date('m'),
            'day' => date('d'),
        ];
        $peopleSituation = [
            'attendance' => random_int(11, 400),
            'visitors' => random_int(11, 100),
        ];
        $usageRata = [
            'liftRate' => random_int(0,100),
            'labRate' => random_int(0,100),
            'lineRate' => random_int(0,100),
            'parkingRate' => random_int(0,100),
            'lightingRate' => random_int(0,100),
            'powerRate' => random_int(0, 100)
        ];
        $responseJson = [
            'code' => 200,
            'message' => '',
            'data' => [
                'date' => $date,
                'weather' => $weatherInfo,
                'airCondition' => $airCondition,
                'peopleSituation' => $peopleSituation,
                'usageRate' => $usageRata,
            ]
        ];
        return response()->json($responseJson);
    }
}
